
package com.dps.omc.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dps.omc.model.SubjectArtifact;
import com.dps.omc.service.ISubjectArtifactService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dps.common.domain.view.BizData4Page;
import com.dps.common.utils.IdGenerator;
import com.dps.common.utils.JsonResult;
import com.dps.common.utils.PageParam;
import com.dps.common.utils.Constants;

@Controller
public class SubjectArtifactAction extends AbstractAdminController<ISubjectArtifactService>{

    @Autowired
    private ISubjectArtifactService subjectArtifactService;
    
    @RequestMapping(value="/subjectartifact/list")
    public String list(SubjectArtifact subjectArtifact, ModelMap model, PageParam pageParam, HttpServletRequest request, HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(subjectArtifact); 	
    	BizData4Page<SubjectArtifact> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("subjectArtifact", subjectArtifact);
    	return "/module/subjectartifact/list";
    }    
    
    @RequestMapping(value="/subjectartifact/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("subjectArtifact", new SubjectArtifact());
        return "module/subjectartifact/edit";
    }    
    
    @RequestMapping(value="/subjectartifact/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	SubjectArtifact subjectArtifact = subjectArtifactService.fetch(id);
    	model.addAttribute("subjectArtifact", subjectArtifact);
        return "module/subjectartifact/edit";
    }    
    
    @RequestMapping(value="/subjectartifact/save")
    @ResponseBody
    public String save(HttpServletRequest request,SubjectArtifact subjectArtifact){
		boolean isAddNew = StringUtils.isBlank(subjectArtifact.getId())?true:false;
		if(isAddNew)
		{
			subjectArtifact.setId(IdGenerator.createNewId());
			subjectArtifactService.add(subjectArtifact);
		}
		else
		{
			subjectArtifactService.update(subjectArtifact);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/subjectartifact/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	subjectArtifactService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(SubjectArtifact subjectArtifact)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("subjectId", subjectArtifact.getSubjectId());		
		conditions.put("artifactId", subjectArtifact.getArtifactId());		
		conditions.put("createrId", subjectArtifact.getCreaterId());		
		conditions.put("createrName", subjectArtifact.getCreaterName());		
		conditions.put("createDate", subjectArtifact.getCreateDate());		
    	return conditions;
    }

    @Override
    protected ISubjectArtifactService getMainService() {
        return subjectArtifactService;
    }

    @Override
    protected String getMainObjName() {
        return "subjectartifact";
    }

    @Override
    protected String getViewTitle() {
        return "subjectartifact";
    }
}
